package com.siwei.infoextract.web;

import java.util.Date;
import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ahxu.crawler.CrawlerManager;

public class InfoExtractInitializer implements ServletContextListener {
	
	Log logger = LogFactory.getLog(InfoExtractInitializer.class);

	Timer timer = null;

	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		logger.info("Timer is canceling");
		timer.cancel();
		logger.info("Timer has been canceled");
	}

	public void contextInitialized(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		logger.info("Timer is starting");
		timer = new Timer();
		logger.info("Timer has been started");

		logger.info("Scheduling info extract process");
		// Every 1 minute
		timer.schedule(new InfoProcessor(), new Date(), 1 * 60 * 1000);
		logger.info("Has been scheduled info extract process");
	}

}
